#docker run -ti -v "$(pwd)/mount/":/mount -p 8022:22 -p 8021:21 ubuntu:22.04 /bin/bash

FROM ubuntu:22.04

MAINTAINER libo libo@swust.edu.cn

#ENV REFRESHED_AT 2018-10-15

USER root

ENV DEBIAN_FRONTEND=noninteractive

COPY sources.list /etc/apt/

RUN apt-get update && apt-get -yq dist-upgrade \
 && apt-get install -yq --no-install-recommends \
    openssh-server \
    wput \
    vsftpd \
    make \
    sudo \
    less \
    bsdmainutils \
    curl \
    python3-pip \
 && apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# Configure environment
ENV SHELL=/bin/bash \
    LC_ALL=en_US.UTF-8 \
    LANG=en_US.UTF-8 \
    LANGUAGE=en_US.UTF-8

# install linuxer for ssh access
COPY linuxer.tar.gz /root
RUN cd /root; tar -xvzf linuxer.tar.gz
RUN cd /root/linuxer; make install

# configure vsftp
RUN printf "/opt/linuxer/bin/server.bash\n\
/opt/linuxer/bin/server-students.bash\n\
/opt/linuxer/bin/server-teachers.bash\n"\
>> /etc/shells 
RUN cp /root/linuxer/etc/sudoers.d/linuxer /etc/sudoers.d/
RUN echo "write_enable=YES" >>/etc/vsftpd.conf

# remove linuxer install package and directory
RUN rm /root/linuxer.tar.gz; rm -rf /root/linuxer/

# install jupyter
RUN pip3 install -i https://mirrors.aliyun.com/pypi/simple pip --upgrade
RUN pip3 install -i https://mirrors.aliyun.com/pypi/simple jupyter
RUN pip3 install -i https://mirrors.aliyun.com/pypi/simple bash_kernel
RUN python3 -m bash_kernel.install

# add users
RUN useradd -m -s /opt/linuxer/bin/server.bash linuxer
RUN echo "linuxer:linux2021" |chpasswd linuxer

RUN useradd -m -G sudo -s /opt/linuxer/bin/server-teachers.bash teacher
RUN echo "teacher:linux2021" |chpasswd teacher

RUN groupadd students
RUN useradd --badname -m -g students -s /opt/linuxer/bin/server-students.bash 5120180001
RUN echo "5120180001:linux2021" |chpasswd 5120180001

EXPOSE 22 21 8888

COPY entry.sh /usr/local/bin/
